package com.lz.demo5;

/**
 * @ClassName ComputerMajor
 * @Description 计算机专业类
 * @Author 2214361854
 * @Date 2022/5/28 15:00
 * @Version 1.0
 */
public class ComputerMajor extends Major {
    //10.添加子类独有的属性:编程课成绩
    private double programmingScore;

    //11.生成子类自己的全参构造
    public ComputerMajor(double programmingScore, double englishScore, double midScore, double finalScore) {
        //这里是在调用父类的构造方法,因为英文 期中 期末 成绩都是在父类那里赋值的
        super(englishScore, midScore, finalScore);
        //在子类的构造方法中只需要给子类的特有属性专业课成绩赋值即可
        this.programmingScore = programmingScore;
    }

    //12.子类重写父类的getScore(),具体实现总分数的计算
    @Override
    public double getScore() {
        //计算逻辑:总成绩=专业课成绩40%+英文课成绩10%+期中成绩15%+期末成绩35%
        totalScore = programmingScore * 0.4 + englishScore * 0.1 + midScore * 0.15 + finalScore * 0.35;
        //返回计算好的成绩
        return totalScore;
    }

    //13.重写toString()方法,方便直接查看专业类的所有属性值
    @Override
    public String toString() {
        return "计算机专业{" +
                "编程课成绩:" + programmingScore +
                ",英文课成绩:" + englishScore +
                ",期中成绩:" + midScore +
                ",期末成绩:" + finalScore +
                '}';
    }
}

